import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from '../views/home/main.vue'

import HomeRoutes from '../views/home/router'
import TypeRoutes from '../views/types/router'
import CartRoutes from '../views/cart/router'
import myRoutes from '../views/my/router'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Main',
    component: Main,
    redirect: '/index',
    children: [
      ...HomeRoutes
    ]
  },
  {
    path: '/type',
    name: 'typesMain',
    component: () => import('../views/types/main.vue'),
    redirect: '/type/index',
    children: [
      ...TypeRoutes
    ],

  }, 
  {
    path: '/cart',
    name: 'cartMain',
    component: () => import('../views/cart/main.vue'),
    redirect: '/cart/index',
    children: [
      ...CartRoutes
    ],

  },
  {
    path: '/my',
    name: 'myMain',
    component: () => import('../views/my/main.vue'),
    redirect: '/my/index',
    children: [
      ...myRoutes
    ],

  },

]


const router = new VueRouter({
  routes
})


const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  if(typeof(location)=="string"){
    var Separator = "&";
    if(location.indexOf('?')==-1) { Separator='?'; }
    location = location + Separator + "random=" + Math.random();
  }
  return routerPush.call(this, location).catch(error=> error)
}

export default router
